package com.vcarecity.handler;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 *   配置拦截器拦截的方法
 */

@Configuration
public class WebMvcConfig   {
    @Resource
    private AccessTokenInterceptor accessTokenInterceptor;

    @Bean
   public WebMvcConfigurer webMvcConfigurer(){
       return new WebMvcConfigurer() {
           public void addInterceptors(InterceptorRegistry registry){
               //拦截所有请求
               String[] addPathPatterns = {"/**"};
               //不需要拦截的请求
               String[] excludePathPatterns = {"/auth/*"};
               registry.addInterceptor(accessTokenInterceptor).addPathPatterns(addPathPatterns).excludePathPatterns(excludePathPatterns);
           };
       };
   }
}